#include "numericBinaryOperation.h"

NumericBinaryOperation::NumericBinaryOperation(Expression * leftExpresion, std::string opRep, Expression * rightExpression)
{
	if(leftExpresion != NULL) leftOperand =leftExpresion->clone();
	else leftOperand = NULL;

	operatorRepresentation = opRep;

	if(rightExpression != NULL) rightOperand = rightExpression->clone();
	else rightOperand = NULL;
}

NumericBinaryOperation::NumericBinaryOperation(const NumericBinaryOperation & other)
{
    if(other.leftOperand != NULL) leftOperand = other.leftOperand->clone();
	else leftOperand = NULL;

	operatorRepresentation = other.operatorRepresentation;

	if(other.rightOperand != NULL) rightOperand = other.rightOperand->clone();
	else rightOperand = NULL;
}

NumericBinaryOperation::~NumericBinaryOperation()
{
    delete leftOperand; leftOperand = NULL;
    delete rightOperand; rightOperand = NULL;
}

Expression * NumericBinaryOperation::clone()
{
    return new NumericBinaryOperation(*this);
}

std::string NumericBinaryOperation::toString()
{
    std::string str = "(";
    if(leftOperand != NULL) str = str + leftOperand->toString();
    str = str + " " + operatorRepresentation + " ";
    if(rightOperand != NULL) str = str + rightOperand->toString();
    return str + ")";
}

Expression * NumericBinaryOperation::getRightExpression()
{
    return rightOperand;
}

Expression * NumericBinaryOperation::getLeftExpression()
{
    return leftOperand;
}

void NumericBinaryOperation::setRightExpression(Expression * expression)
{
    delete rightOperand; rightOperand = NULL;
    if(expression != NULL) rightOperand = expression->clone();
}

void NumericBinaryOperation::setLeftExpression(Expression * expression)
{
    delete leftOperand; leftOperand = NULL;
    if(expression != NULL) leftOperand = expression->clone();
}

void NumericBinaryOperation::setOperator(const std::string & opRep)
{
    operatorRepresentation = opRep;
}

std::string NumericBinaryOperation::getOperator()
{
    return operatorRepresentation;
}
